import { $get } from '@js/authRequest'

// 获取字典信息
export async function getDictinarys () {
  const res = await $get('/api/xapc/dictionary', {
    types: '结案类型,仲裁程序,案件区域分类,案件来源,受理案件类型'
  })
  if (res.status !== 1) {
    throw new Error(res.message)
  }
  return formatDictionaries(res.data)
}

// 格式化枚举字典
function formatDictionaries (dictionaries = []) {
  const result = {}
  dictionaries.forEach(d => {
    result[d.type] = d.list
  })
  return result
}

// 获取案由树
export async function getTreeData () {
  const res = await $get('/api/common/cause_action')
  if (res.status !== 1) {
    throw new Error(res.message)
  }
  return res.data
}

// 获取案件类型树
export async function getCaseTypeTree () {
  const res = await $get('/api/xapc/dictionary/getTreeByType', {
    type: '案件分类'
  })
  if (res.status !== 1) {
    throw new Error(res.message)
  }
  return res.data
}
